package ar.com.bdf.ipharma.stress;

import java.util.ArrayList;
import java.util.List;

import ar.com.bdf.ipharma.stress.operation.OperationAbrirPuerta;
import ar.com.bdf.ipharma.stress.operation.OperationCerrarPuerta;
import ar.com.bdf.ipharma.stress.operation.OperationExtraer;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class Test {
	public static void main(String[] args) {
		XStream xstream = getXstreamConfigure();
		
		Task task = new Task();
		task.setPort("COM3");
		task.setTimeInterOperation(3L);
		task.setOperations(getOperationsExample());
		
		System.out.println(xstream.toXML(task));
	}
	
	private static List<Operation> getOperationsExample() {
		List<Operation> operations = new ArrayList<Operation>();
		
		operations.add(new OperationExtraer(1,1,1));
		operations.add(new OperationAbrirPuerta());
		operations.add(new OperationCerrarPuerta());
		
		return operations;
	}

	private static XStream getXstreamConfigure() {
		XStream xStream = new XStream(new DomDriver());
		xStream.alias(Task.class.getSimpleName(), Task.class);
		xStream.omitField(Task.class, "parser");
		xStream.useAttributeFor(Task.class, "port");
		xStream.useAttributeFor(Task.class, "timeInterOperation");
		
		xStream.omitField(Operation.class, "handShake");
		xStream.omitField(Operation.class, "factory");
		xStream.useAttributeFor(Operation.class, "countOperation");
		xStream.alias(OperationExtraer.class.getSimpleName(), OperationExtraer.class);
		
		xStream.useAttributeFor(OperationExtraer.class, "cantVueltas");
		xStream.useAttributeFor(OperationExtraer.class, "posicionRulo");
		xStream.useAttributeFor(OperationExtraer.class, "nivel");
		
		xStream.alias(OperationAbrirPuerta.class.getSimpleName(), OperationAbrirPuerta.class);
		xStream.alias(OperationCerrarPuerta.class.getSimpleName(), OperationCerrarPuerta.class);

		return xStream;
	}
}
